const AbsCommand = require('./AbsCommand');
const webContentUtil = require('../utils/webContentUtil');
const windowUtil = require('../utils/windowUtil');
const configUtil = require('../utils/configUtil');

class ConfigCommand extends AbsCommand {
  async execute() {
    const mainWindow = webContentUtil.getMainWindow();
    let configWindow = windowUtil.createModalWindow(mainWindow, 'config.html', 600, 400);
    configWindow.on('closed', () => {
      configWindow = null;
    });

    configWindow.webContents.on('dom-ready', async () => {
      try {
        const config = await configUtil.loadConfig();
        configWindow.webContents.send('config', config);
      } catch (e) {
        console.error(e);
      }
    });
  }
}

module.exports = ConfigCommand;
